package com.zmn.oms.services.impl.wechatwork;

import com.zmn.base.plat.engine.common.constant.PlatEngineConsts;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.oms.model.entity.wechatwork.OmsOrderWechatWorkLog;
import com.zmn.oms.model.entity.wechatwork.OmsOrderWechatWorkLogQuery;
import com.zmn.oms.persistence.interfaces.wechatwork.OmsOrderWechatWorkLogDao;
import com.zmn.oms.services.interfaces.wechatwork.OmsOrderWechatWorkLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 接口实现类
 *
 * @author guoqiao
 * @since 2022/08/29 16:07
 */
@Slf4j
@Service
public class OmsOrderWechatWorkLogServiceImpl implements OmsOrderWechatWorkLogService {

    private static final String TAG = "基础服务接口";

    @Resource
    private OmsOrderWechatWorkLogDao omsOrderWechatWorkLogDao;

    @Override
    public OmsOrderWechatWorkLog findById(Integer enterpriseId) {
        if (Objects.isNull(enterpriseId)) {
            log.error("[{}],根据id查询数据enterpriseId为null", TAG);
            return null;
        }
        return omsOrderWechatWorkLogDao.findById(enterpriseId);
    }

    @Override
    public List<OmsOrderWechatWorkLog> listByIds(List<Integer> enterpriseIds) {
        if (CollectionUtils.isEmpty(enterpriseIds)) {
            log.error("[{}],按条件查询数据,enterpriseIds为null", TAG);
            return Collections.emptyList();
        }
        return omsOrderWechatWorkLogDao.listByIds(enterpriseIds);
    }

    @Override
    public List<OmsOrderWechatWorkLog> listByQuery(OmsOrderWechatWorkLogQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return Collections.emptyList();
        }
        return omsOrderWechatWorkLogDao.listByQuery(query);
    }

    @Override
    public List<OmsOrderWechatWorkLog> listPageByQuery(OmsOrderWechatWorkLogQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return Collections.emptyList();
        }
        if (NumberUtil.isNullOrZero(query.getTotalCount())) {
            query.setTotalCount(countByQuery(query));
        }
        return omsOrderWechatWorkLogDao.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(OmsOrderWechatWorkLogQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return GlobalConsts.NONE;
        }
        return omsOrderWechatWorkLogDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(OmsOrderWechatWorkLog omsOrderWechatWorkLog) {
        if (Objects.isNull(omsOrderWechatWorkLog.getEnterpriseId())) {
            log.error("[{}],根据id修改数据,omsOrderWechatWorkLog为null", TAG);
            return GlobalConsts.NONE;
        }
        return omsOrderWechatWorkLogDao.updateByKey(omsOrderWechatWorkLog);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {
        if (!Objects.equals(status, PlatEngineConsts.NO) && !Objects.equals(status, PlatEngineConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        omsOrderWechatWorkLogDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(OmsOrderWechatWorkLog omsOrderWechatWorkLog) {
        if (Objects.isNull(omsOrderWechatWorkLog)) {
            log.error("[{}],新增数据,omsOrderWechatWorkLog为null", TAG);
            return GlobalConsts.NONE;
        }
        return omsOrderWechatWorkLogDao.insert(omsOrderWechatWorkLog);
    }

    @Override
    public void insertBatch(List<OmsOrderWechatWorkLog> list) {
        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        omsOrderWechatWorkLogDao.insertBatch(list);
    }

    @Override
    public Integer deleteByKey(Integer enterpriseId) {
        if (Objects.isNull(enterpriseId)) {
            log.error("[{}],根据id删除数据,enterpriseId为null", TAG);
            return GlobalConsts.NONE;
        }
        return omsOrderWechatWorkLogDao.deleteByKey(enterpriseId);
    }

}